//初始化项目信息
$certusUtils.ajax("loadProInfo", {
    "proId": proId
}, function (res) {
    proBaseInfo = res.data;
    projectType = proBaseInfo.proType;
    //项目详情页 左边栏 权限控制
    $certusUtils.ajax("leftMenuAuthority", {
        "projType": projectType,
        "projId": proId
    }, function (res) {
        if (res.data) {
            $$scope.leftMenu = res.data;
            $$scope.warnIs = $$scope.leftMenu['XMYBP-XMZB-XZC'];
            $$scope.targetIs = $$scope.leftMenu['XMYBP-XMMB-GXU'];
            // if ($$scope.leftMenu['KHGL-KHGL']==undefined){
            $$scope.isKHGL = true; //$$scope.leftMenu['KHGL-KHGLR'];
            // }else{
            //     $$scope.isKHGL = $$scope.leftMenu['KHGL-KHGL']
            // }
            $$scope.isYSHFY = $$scope.leftMenu['YSHFY-YSXX'];
            loadWarn();
            loadTarget();
        }
    });
});
// 项目目标
var prointColumns = [{
    id: 'proTarget',
    title: '项目目标',
    type: 'string',
    columnClass: 'text-left',
}, {
    id: 'userName',
    title: '目标负责人',
    type: 'string',
    width: 90,
    columnClass: 'text-center',
}, {
    id: 'finishTime',
    title: '完成时间',
    type: 'date',
    format: 'yyyy-MM-dd',
    otype: 'time_stamp_ms',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'operation',
    title: '操作',
    width: 130,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record) {
        var updateTarget = "updateTarget('" + record.id + "')";
        var delTarget = "delTarget('" + record.id + "')";
        var met = {
            'XMYBP-XMMBU': updateTarget,
            'XMYBP-XMMBD': delTarget
        };
        content = $certusUtils.initOperateAutho($$scope.leftMenu, ['XMYBP-XMMBU%edit', 'XMYBP-XMMBD%delete'], met, proinColumns);
        return content;
    }
}];

function loadTarget() {
    // $("#prointContainer").empty();
    // $certusUtils.ajax("findTargets", {
    //     "proId": proId
    // }, function (response) {
    //     var proinOption = {
    //         lang: 'zh-cn',
    //         ajaxLoad: false,
    //         extraWidth: 20,
    //         // loadURL:'url',
    //         exportFileName: '项目指标',
    //         datas: response.data,
    //         columns: prointColumns,
    //         gridContainer: 'prointContainer',
    //         tools: '',
    //     };
    //     var proinGrid = $.fn.dlshouwen.grid.init(proinOption);
    //     proinGrid.load();
    // });
}

// 项目指标
var proinColumns = [{
    id: 'wntyName',
    title: '指标名称',
    width: 160,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'wntyDesc',
    title: '指标描述',
    type: 'string',
    columnClass: 'text-left',
}, {
    id: 'finishTime',
    title: '完成时间',
    type: 'date',
    width: 100,
    columnClass: 'text-center'
}, {
    id: 'operation',
    title: '操作',
    width: 130,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record) {
        var updateWarn = "updateWarn('" + record.id + "')";
        var delWarn = "delWarn('" + record.id + "')";
        var met = {
            'XMYBP-XMMBU': updateWarn,
            'XMYBP-XMMBD': delWarn
        };
        content = $certusUtils.initOperateAutho($$scope.leftMenu, ['XMYBP-XMMBU%edit', 'XMYBP-XMMBD%delete'], met, proinColumns);
        return content;
    }
}];

function loadWarn() {
    // $("#proinContainer").empty();
    // $("#proinToolBarContainer").empty();
    // $certusUtils.ajax("findWarnList", {
    //     "proId": proId
    // }, function (response) {
    //     var proinOption = {
    //         lang: 'zh-cn',
    //         ajaxLoad: false,
    //         extraWidth: 20,
    //         // loadURL:'url',
    //         exportFileName: '项目指标',
    //         datas: response.data,
    //         columns: proinColumns,
    //         gridContainer: 'proinContainer',
    //         toolbarContainer: 'proinToolBarContainer',
    //         tools: '',
    //         pageSize: 10,
    //         pageSizeLimit: [10, 15, 20]
    //     };
    //     var proinGrid = $.fn.dlshouwen.grid.init(proinOption);
    //     proinGrid.load();
    // });
}

$certusUtils.ajax('findRoleCostList',{"proId":proId},function (response) {
    var rlColumns = [{
        id: 'roleName',
        title: '角色',
        type: 'string',
        columnClass: 'text-center'
    },{
        id: 'level',
        title: '级别',
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '';
            if (value=="1"){
                content = "低";
            }else if (value=="2"){
                content = "中";
            }else{
                content = "高";
            }
            return content;
        }
    },{
        id: 'beginTime',
        title: '开始时间',
        type: 'date',
        format: 'yyyy-MM-dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center',
    }, {
        id: 'endTime',
        title: '结束时间',
        type: 'date',
        format: 'yyyy-MM-dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center',
    },{
        id: 'rtNum',
        title: '人天',
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'comments',
        title: '说明',
        type: 'string',
        columnClass: 'text-center',
    }];
    var rlOption = {
        lang: 'zh-cn',
        ajaxLoad: false,
        extraWidth: 20,
        // loadURL:'url',
        exportFileName: '人力成本列表',
        datas: response.data,
        columns: rlColumns,
        gridContainer: 'rlContainer'
    };
    var rlGrid = $.fn.dlshouwen.grid.init(rlOption);
    rlGrid.load();
});

$certusUtils.ajax('findProFileList',{"proId":proId},function (response) {
    var wjColumns = [{
        id: 'productName',
        title: '文件名称',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'comments',
        title: '说明',
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'createUserName',
        title: '创建人',
        type: 'string',
        columnClass: 'text-center'
    }];
    var wjOption = {
        lang: 'zh-cn',
        ajaxLoad: false,
        extraWidth: 20,
        // loadURL:'url',
        exportFileName: '涉及文件列表',
        datas: response.data,
        columns: wjColumns,
        gridContainer: 'wjContainer'
    };
    var wjGrid = $.fn.dlshouwen.grid.init(wjOption);
    wjGrid.load();
});

function delWarn(id) {
    layer.confirm('是否确认删除？', {
        btn: ['确定', '取消'] //按钮
    }, function (index) {
        layer.msg('删除成功');
        $certusUtils.ajax("toDelWarn", {
            "warnId": id,
            "projId": proId
        }, function (response) {
            loadWarn();
        });
    });
}

function updateWarn(id) {
    toLoadHtml(3, id);
}

$(".addWarn").on('click', function () {
    toLoadHtml(2)
});

var date = new Date;
var year = date.getFullYear();
$("#ckYear").val(year);

function phaseTjs(proId) {
    $certusUtils.ajax('findPros', {
        "proId": proId
    }, function (response) {
        var ptype = response.data.proType;
        if (ptype == "XS") {
            var totalRt = 0;
            var totalMoney = 0;
            $certusUtils.ajax('findPhaseTjs', {
                "param": proId,
                "year": year,
                "compCode": ""
            }, function (response) {
                var data = response.data;
                var yccost = [];
                var sjcost = [];
                var ycrt = [];
                var sjrt = [];

                var forecastcost = 0;
                var actualcost = 0;
                var forecastday = 0;
                var actualday = 0;

                for (var i = 0; i < data.length; i++) {
                    totalRt += data[i].actualday;
                    totalMoney += data[i].actualcost;
                    if (data[i].phase == "XS") {
                        yccost[0] = data[i].forecastcost;
                        sjcost[0] = data[i].actualcost;
                        ycrt[0] = data[i].forecastday;
                        sjrt[0] = data[i].actualday;
                    } else if (data[i].phase == "LX"||data[i].phase == "TB") {
                        forecastcost+=data[i].forecastcost;
                        actualcost+=data[i].actualcost;
                        forecastday+=data[i].forecastday;
                        actualday+=data[i].actualday;
                    } else if (data[i].phase == "TB") {
                        yccost[2] = data[i].forecastcost;
                        sjcost[2] = data[i].actualcost;
                        ycrt[2] = data[i].forecastday;
                        sjrt[2] = data[i].actualday;
                    } else if (data[i].phase == "JF") {
                        yccost[3] = data[i].forecastcost;
                        sjcost[3] = data[i].actualcost;
                        ycrt[3] = data[i].forecastday;
                        sjrt[3] = data[i].actualday;
                    } else {
                        yccost[4] = forecastcost;
                        sjcost[4] = actualcost;
                        ycrt[4] = forecastday;
                        sjrt[4] = actualday;
                    }
                }

                yccost[1] = forecastcost;
                sjcost[1] = actualcost;
                ycrt[1] = forecastday;
                sjrt[1] = actualday;

                var myChart1 = echarts.init(document.getElementById('main2'));
                option = {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            crossStyle: {
                                color: '#999'
                            }
                        }
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    legend: {
                        data: ['预测成本', '实际成本', '预测人天', '实际人天']
                    },
                    xAxis: [{
                        type: 'category',
                        data: ['线索', '运作', '交付', '回款'],
                        axisPointer: {
                            type: 'shadow'
                        }
                    }],
                    yAxis: [{
                        type: 'value',
                        name: '元',
                        axisLabel: {
                            formatter: '￥{value}'
                        }
                    },
                        {
                            type: 'value',
                            name: '人/天',
                            axisLabel: {
                                formatter: '{value}'
                            }
                        }
                    ],
                    series: [{
                        name: '预测成本',
                        type: 'bar',
                        barWidth: '15px',
                        data: yccost
                    },
                        {
                            name: '实际成本',
                            type: 'bar',
                            barWidth: '15px',
                            data: sjcost
                        },
                        {
                            name: '预测人天',
                            type: 'line',
                            yAxisIndex: 1,
                            data: ycrt
                        },
                        {
                            name: '实际人天',
                            type: 'line',
                            yAxisIndex: 1,
                            data: sjrt
                        }
                    ]
                };
                myChart1.setOption(option);
            });
        }else{
            $("#isHide").hide();
        }
    });
};
// phaseTjs(proId);

function getMonthTb(year) {
    $certusUtils.ajax('findMonthTjs', {
        "param": proId,
        "year": year,
        "compCode": ""
    }, function (response) {
        var data = response.data;
        var yccost = [];
        var sjcost = [];
        var ycrt = [];
        var sjrt = [];
        for (var i = 0; i < data.length; i++) {
            yccost[i] = data[i].yccost;
            sjcost[i] = data[i].sjcost;
            ycrt[i] = data[i].ycpercent / 100;
            sjrt[i] = data[i].sjpercent / 100;
        }
        var myChart2 = echarts.init(document.getElementById('main8'));
        option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    crossStyle: {
                        color: '#999'
                    }
                }
            },
            // toolbox: {
            //     feature: {
            //         dataView: {
            //             show: true,
            //             readOnly: true
            //         },
            //         magicType: {
            //             show: true,
            //             type: ['line', 'bar']
            //         },
            //         restore: {
            //             show: true
            //         },
            //         saveAsImage: {
            //             show: false
            //         }
            //     }
            // },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '5%',
                containLabel: true
            },
            legend: {
                data: ['预测成本', '实际成本', '预测人天', '实际人天']
            },
            xAxis: [{
                type: 'category',
                data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月',
                    '11月', '12月'
                ],
                axisPointer: {
                    type: 'shadow'
                }
            }],
            yAxis: [{
                type: 'value',
                name: '元',
                axisLabel: {
                    formatter: '￥{value}'
                }
            },
                {
                    type: 'value',
                    name: '人/天',
                    axisLabel: {
                        formatter: '{value}'
                    }
                }
            ],
            series: [{
                name: '预测成本',
                type: 'bar',
                barWidth: '10%',
                data: yccost
            },
                {
                    name: '实际成本',
                    type: 'bar',
                    barWidth: '10%',
                    data: sjcost
                },
                {
                    name: '预测人天',
                    type: 'line',
                    yAxisIndex: 1,
                    data: ycrt
                },
                {
                    name: '实际人天',
                    type: 'line',
                    yAxisIndex: 1,
                    data: sjrt
                }
            ]
        };
        myChart2.setOption(option);
    });
}

// getMonthTb($("#ckYear").val());

function changeYear(pyear) {
    getMonthTb(pyear);
}

this.bussesPhasTjs = function (proId) {
    $certusUtils.ajax('loadProInfo', {
        "proId": proId
    }, function (response) {
        var date = new Date;
        var year = date.getFullYear();
        var ptype = response.data.proType;
        if (ptype == "XS") {
            $certusUtils.ajax('findBussesPhasTjs', {
                "param": proId,
                "year": year,
                "compCode": ""
            }, function (response) {
                var data = response.data;
                var bugetlist = data.bugetList;
                var treimDays = data.treimDays;
                var yccost = [];
                var sjcost = [];
                for (var i = 0; i < bugetlist.length; i++) {
                    yccost[i] = bugetlist[i].buget;
                }
                var yzCost = 0;
                for (var i = 0; i < treimDays.length; i++) {
                    if (treimDays[i].phase == "XS") {
                        sjcost.push(treimDays[i].cost);
                    } else if (treimDays[i].phase == "LX"||treimDays[i].phase == "TB") {
                        yzCost+=treimDays[i].cost;
                    }  else if (treimDays[i].phase == "JF") {
                        sjcost.push(treimDays[i].cost);
                    } else {
                        sjcost.push(treimDays[i].cost);
                    }
                }
                sjcost.push(yzCost);
                var myChart2 = echarts.init(document.getElementById('main4'));
                option = {
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['预测费用', '实际费用']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    // toolbox: {
                    //     feature: {
                    //         saveAsImage: {}
                    //     }
                    // },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: ["线索", "运作","交付", "回款"]
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                            name: '预测费用',
                            type: 'line',
                            data: yccost
                        },
                        {
                            name: '实际费用',
                            type: 'line',
                            data: sjcost
                        }
                    ]
                };

                myChart2.setOption(option);
            });
        } else {
            $certusUtils.ajax('getYbpPhases', {
                "param": proId,
                "year": year
            }, function (response) {
                var arr = [];
                var sjarr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
                var dd = response.data;
                for (var i = 0; i < dd.length; i++) {
                    arr.push(dd[i].buget);
                }
                var myChart2 = echarts.init(document.getElementById('main4'));
                option = {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            crossStyle: {
                                color: '#999'
                            }
                        }
                    },
                    // toolbox: {
                    //     feature: {
                    //         dataView: {
                    //             show: true,
                    //             readOnly: true
                    //         },
                    //         magicType: {
                    //             show: true,
                    //             type: ['line', 'bar']
                    //         },
                    //         restore: {
                    //             show: true
                    //         },
                    //         saveAsImage: {
                    //             show: false
                    //         }
                    //     }
                    // },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '5%',
                        containLabel: true
                    },
                    legend: {
                        data: ['预测成本', '实际成本'],
                        left: 50
                    },
                    xAxis: [{
                        type: 'category',
                        data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月',
                            '11月', '12月'
                        ],
                        axisPointer: {
                            type: 'shadow'
                        }
                    }],
                    yAxis: [{
                        type: 'value',
                        name: '元',
                        axisLabel: {
                            formatter: '￥{value}'
                        }
                    }],
                    series: [{
                            name: '预测成本',
                            type: 'bar',
                            barWidth: '10%',
                            data: arr
                        },
                        {
                            name: '实际成本',
                            type: 'bar',
                            barWidth: '10%',
                            data: sjarr
                        }
                    ]
                };
                myChart2.setOption(option);
            });
        }
    });
};
// bussesPhasTjs(proId);
//项目采购按月分布
this.cgTjs = function (proId) {
    var date = new Date;
    var year = date.getFullYear();
    $certusUtils.ajax('findCgTjs', {
        "param": proId,
        "year": year,
        "compCode": ""
    }, function (response) {
        var data = response.data;
        var yctjs = data.cgycs;
        var sjtjs = data.cgsjs;
        var ycsys = [];
        var yczys = [];
        var ycwls = [];
        var sjsys = [];
        var sjzys = [];
        var sjwls = [];
        var cgtotalMoney = 0;
        var cgsymoney = 0;
        for (var i = 0; i < yctjs.length; i++) {
            if (yctjs[i].code == "SY") {
                ycsys.push(yctjs[i].totalMoney);
            } else if (yctjs[i].code == "ZY") {
                yczys.push(yctjs[i].totalMoney);
            } else {
                ycwls.push(yctjs[i].totalMoney);
            }
        }
        for (var i = 0; i < sjtjs.length; i++) {
            if (sjtjs[i].code == "SY") {
                cgsymoney += yctjs[i].totalMoney;
                sjsys.push(yctjs[i].totalMoney);
            } else if (sjtjs[i].code == "ZY") {
                cgtotalMoney += yctjs[i].totalMoney;
                sjzys.push(yctjs[i].totalMoney);
            } else {
                cgtotalMoney += yctjs[i].totalMoney;
                sjwls.push(yctjs[i].totalMoney);
            }
        }
        var cgMoney = cgtotalMoney + cgsymoney;
        var myChart2 = echarts.init(document.getElementById('main7'));
        option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: { // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            legend: {
                data: ['预测商用', '预测自用', '预测外联', '实际商用', '实际自用', '实际外联']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [{
                type: 'category',
                data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月',
                    '11月', '12月'
                ]
            }],
            yAxis: [{
                type: 'value'
            }],
            series: [{
                    name: '预测商用',
                    type: 'bar',
                    barWidth: '10%',
                    stack: '预测采购费用',
                    data: ycsys
                },
                {
                    name: '实际商用',
                    type: 'bar',
                    barWidth: '10%',
                    stack: '实际采购费用',
                    data: sjsys
                },
                {
                    name: '预测自用',
                    type: 'bar',
                    barWidth: '10%',
                    stack: '预测采购费用',
                    data: yczys
                },
                {
                    name: '实际自用',
                    type: 'bar',
                    barWidth: '10%',
                    stack: '实际采购费用',
                    data: sjzys
                },
                {
                    name: '预测外联',
                    type: 'bar',
                    barWidth: '10%',
                    stack: '预测采购费用',
                    data: ycwls
                }, {
                    name: '实际外联',
                    type: 'bar',
                    barWidth: '10%',
                    stack: '实际采购费用',
                    data: sjwls
                }
            ]
        };
        myChart2.setOption(option);
    });
};
// cgTjs(proId);
//项目基本信息
$certusUtils.ajax("findProDetaiInfo", {
    "proId": proId
}, function (response) {
    var data = response.data.proMap;
    $("#proNo").html(data.pro_no);
    //阶段code
    var stageCode = data.stage_code;
    var stalist = [data.xslx_time,data.prolx_time,data.tbsq_time,data.prozyTime,data.proJfTime,data.proHkTime];

    for(var i=0;i< stalist.length;i++){
        if(stalist[i] == undefined || stalist[i] == "" || stalist[i] == null){
            $(".pro-phase ul li").eq(i).find("label").append("")
        }
        if (i == 0){
            $(".pro-phase ul li").eq(0).find("label").append(stalist[i])
        }
        if (i == 1 || i == 2){
            var time = $(".pro-phase ul li").eq(1).find("label").text()
            if(time == "") {
                $(".pro-phase ul li").eq(1).find("label").append(stalist[i])
            }
        }
        if ( i == 3){
            $(".pro-phase ul li").eq(2).find("label").append(stalist[i])
        }
        if (i == 4) {
            $(".pro-phase ul li").eq(3).find("label").append(stalist[i])
        }
        if (i == 5) {
            $(".pro-phase ul li").eq(4).find("label").append(stalist[i])
        }
    }

    if (stageCode == 1) {
        $(".pro-phase ul").find("li").slice(0,1).addClass("do");
    }else if (stageCode == 2) {
        $(".pro-phase ul").find("li").slice(0,2).addClass("do");
    }else if (stageCode == 3) {
        $(".pro-phase ul").find("li").slice(0,2).addClass("do");
    }else if (stageCode == 4) {
        $(".pro-phase ul").find("li").slice(0,3).addClass("do");
    }else if (stageCode == 5) {
        $(".pro-phase ul").find("li").slice(0,4).addClass("do");
    }else if (stageCode == 6) {
        $(".pro-phase ul").find("li").slice(0,5).addClass("do");
    } else {
        $(".pro-phase ul").find("li").slice(0,6).addClass("do");
    }
    $$scope.proName = data.pro_name;
    if (data.pimportance==0){
        $("#importance").html("一般");
    }else if (data.pimportance==1){
        $("#importance").html("重要");
    }else{
        $("#importance").html("战略");
    }
    if (data.purgency==0){
        $("#urgency").html("不紧急");
    }else{
        $("#urgency").html("紧急");
    }
    var proType = data.pro_type;
    if (proType == "ZL") {
        $("#proType").html("战略类");
    } else if (proType == "YF") {
        $("#proType").html("研发类");
    } else if (proType == "XS") {
        $("#proType").html("销售类");
    } else if (proType == "BM") {
        $("#proType").html("部门类");
    } else if (proType == "SW") {
        $("#proType").html("事务类");
    } else {
        $("#proType").html("测试类");
    }

    if (proType == "XS") {
        $("#showVersion").hide();
        $("#cusName").html(data.cus_name);
        $("#proArea").html(data.pro_area);
        $("#divineSignDate").html(data.divine_sign_date);
        $("#divineHkDate").html(data.divine_hk_date);
        $("#cusPolicy").html(data.cus_policy);
        $("#competitor").html(data.competitor);
        var isCompare = data.is_compare;
        if (isCompare == 1) {
            $("#isCompare").html("有");
        } else {
            $("#isCompare").html("无");
        }
    } else if (proType == "ZL" || proType == "SW" ||
        proType == "BM") {
        $("#htLi").hide();
        $("#jfLi").hide();
        $("#hkLi").hide();

        $("#showCus").hide();
        $("#showArea").hide();
        $("#showCompare").hide();
        $("#showSign").hide();
        $("#showHk").hide();
        $("#showPolucy").hide();
        $("#showPdLine").hide();
        $("#showCompe").hide();
        $("#showBudget").hide();
        $("#showVersion").hide();
        $("#divineFinishTime").html(data.dfTime);
    } else {
        $("#htLi").hide();
        $("#jfLi").hide();
        $("#hkLi").hide();

        $("#showCus").hide();
        $("#showArea").hide();
        $("#showCompare").hide();
        $("#showSign").hide();
        $("#showHk").hide();
        $("#showPolucy").hide();
        $("#showPdLine").hide();
        $("#showCompe").hide();
        $("#showBudget").hide();
        $("#divineVersionTime").html(data.dvTime);
    }
    $("#proName").html(data.pro_name);
    var proLv = data.pro_lv;
    if (proLv == 3) {
        $("#proLv").html("高");
    } else if (proLv == 2) {
        $("#proLv").html("中");
    } else {
        $("#proLv").html("低");
    }
    var proState = data.pro_state;
    if (proState != "1") {
        $("#isAdd").hide();
        $("#isEdit").hide();
    }else{
        if (response.data.isMg==false){
            $("#isAdd").hide();
            $("#isEdit").hide();
        }
    }
    if (proState == 1) {
        $("#proState").html("运行中");
        $("#topState").html('<span class="label label-primary">运行中</span>');
    } else if (proState == 2) {
        $("#proState").html("已关闭");
        $("#topState").html('<span class="label label-danger">已关闭</span>');
    } else if (proState == 3) {
        $("#proState").html("已完结");
        $("#topState").html('<span class="label label-success">已完结</span>');
    } else  if (proState == 4) {
        $("#proState").html("已暂停");
        $("#topState").html('<span class="label label-warning">已暂停</span>');
    }
    $("#clueDesc").html(data.clue_desc);
    $("#proTarget").html(data.pro_target);
    $("#deptName").html(data.deptName);
    $("#mgName").html(data.mgName);
    $("#delName").html(data.delName);
    $("#pduName").html(data.pduName);
    $("#startTime").html(data.startTime);
    $("#endTime").html(data.endTime);
    $("#pdLine").html(response.data.deptNames);

    var mebList = response.data.mebMap;
    // 项目成员
    var other1Columns = [{
        id: 'userName',
        title: '姓名',
        type: 'string',
        width: 130,
        columnClass: 'text-center',
    }, {
        id: 'proRole',
        title: '角色',
        type: 'string',
        columnClass: 'text-left',
    }];
    var other1Option = {
        lang: 'zh-cn',
        ajaxLoad: false,
        extraWidth: 20,
        // loadURL:'url',
        exportFileName: '项目成员',
        datas: mebList,
        columns: other1Columns,
        gridContainer: 'mebContainer',
        toolbarContainer: 'mebContainerPage',
        tools: '',
        pageSize: 10,
        pageSizeLimit: [10, 15, 20]
    };
    var other1Grid = $.fn.dlshouwen.grid.init(other1Option);
    other1Grid.load();
});
//我的职责
// $certusUtils.ajax("findMyJobs", {
//     "proId": proId
// }, function (response) {
//     var data = response.data;
//     var html = "";
//     for (var i = 0; i < data.length; i++) {
//         html += "<p>" + data[i].roleName + "：" + data[i].roleRules + "</p>"
//     }
//     $("#jobContiner").html(html);
// })
//更新项目目标
function updateTarget(id) {
    $certusUtils.ajax("isHasTarget", {
        "targetId": id
    }, function (response) {
        var data = response.data;
        if (data) {
            layer.msg("项目目标存在关联任务，不能修改！");
            return;
        } else {
            toLoadHtml(10, id);
        }
    })
}
$(".addTarget").on('click', function () {
    toLoadHtml("10-1")
});

function delTarget(id) {
    $certusUtils.ajax("isHasTarget", {
        "targetId": id
    }, function (response) {
        var data = response.data;
        if (data) {
            layer.msg("项目目标存在关联任务，不能删除！");
            return;
        } else {

            layer.confirm('是否确认删除？', {
                btn: ['确定', '取消'] //按钮
            }, function (index) {
                layer.msg('删除成功');
                $certusUtils.ajax("delTarget", {
                    "projId": proId,
                    "id": id
                }, function () {
                    toLoadHtml(1);
                })
            });
            // $certusUtils.ajax("delTarget",{"projId":proId,"id":id},function(){
            //     layer.msg("删除成功",{"time":1000});
            //     toLoadHtml(1);
            // })
        }
    })
}